package cn.simon.free.redis.config;

import cn.simon.free.redis.config.properties.RedissonProperties;
import lombok.AllArgsConstructor;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author simon
 * @date 2020/11/18 16:33
 * @copyright:
 * @modifier
 * @motto a no talent, people who have to study hard
 */
@Configuration
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class RedissonConfig {

    private final RedissonProperties redissonProperties;

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() {
        Config config = new Config();
        config.useSingleServer()
                .setAddress(redissonProperties.getAddress())
                .setPassword(redissonProperties.getPassword())
                .setDatabase(redissonProperties.getDatabase())
                .setTimeout(redissonProperties.getTimeout());
        return Redisson.create(config);
    }

}
